<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>PASSWD extended operation helper</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.ldap-escape.html">« ldap_escape</a></li>
      <li style="float: right;"><a href="function.ldap-exop-refresh.html">ldap_exop_refresh »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.ldap.html">LDAP 函数</a></li>
    <li>PASSWD extended operation helper</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.ldap-exop-passwd" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ldap_exop_passwd</h1>
  <p class="verinfo">(PHP 7 &gt;= 7.2.0, PHP 8)</p><p class="refpurpose"><span class="refname">ldap_exop_passwd</span> &mdash; <span class="dc-title">PASSWD extended operation helper</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.ldap-exop-passwd-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ldap_exop_passwd</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="class.ldap-connection.html" class="type LDAP\Connection">LDAP\Connection</a></span> <code class="parameter">$ldap</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$user</code><span class="initializer"> = &quot;&quot;</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$old_password</code><span class="initializer"> = &quot;&quot;</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$new_password</code><span class="initializer"> = &quot;&quot;</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$controls</code><span class="initializer"> = <strong><code>null</code></strong></span></span><br>): <span class="type"><span class="type">string</span>|<span class="type">bool</span></span></div>

  <p class="para rdfs-comment">
   Performs a PASSWD extended operation.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ldap-exop-passwd-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">ldap</code></dt>

    <dd>

     <p class="para">
      通过 <span class="function"><a href="function.ldap-connect.html" class="function">ldap_connect()</a></span> 返回的 <span class="classname"><a href="class.ldap-connection.html" class="classname">LDAP\Connection</a></span> 实例。
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">user</code></dt>

    <dd>

     <p class="para">
       dn of the user to change the password of.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">old_password</code></dt>

    <dd>

     <p class="para">
       The old password of this user. May be ommited depending of server configuration.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">new_password</code></dt>

    <dd>

     <p class="para">
       The new password for this user. May be omitted or empty to have a generated password.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">controls</code></dt>

    <dd>

     <p class="para">
       If provided, a password policy request control is send with the request and this is
       filled with an array of <a href="ldap.controls.html" class="link">LDAP Controls</a>
       returned with the request.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ldap-exop-passwd-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    Returns the generated password if <code class="parameter">new_password</code> is empty or omitted.
    Otherwise returns <strong><code>true</code></strong> on success and <strong><code>false</code></strong> on failure.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.ldap-exop-passwd-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
 <td>8.1.0</td>
 <td>
  现在 <code class="parameter">ldap</code> 参数接受 <span class="classname"><a href="class.ldap-connection.html" class="classname">LDAP\Connection</a></span>
  实例，之前接受 <a href="language.types.resource.html" class="link">资源(resource)</a>。
 </td>
</tr>

      <tr>
<td>8.0.0</td>
<td>
  <code class="parameter">controls</code> is nullable now; previously, it defaulted to <code class="literal">[]</code>.
</td>
</tr>

      <tr>
       <td>7.3.0</td>
       <td>
        Support for <code class="parameter">controls</code> added
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.ldap-exop-passwd-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4342">
    <p><strong>示例 #1 PASSWD extended operation</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$ds&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ldap_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">);&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;assuming&nbsp;the&nbsp;LDAP&nbsp;server&nbsp;is&nbsp;on&nbsp;this&nbsp;host<br /><br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;bind&nbsp;with&nbsp;appropriate&nbsp;dn&nbsp;to&nbsp;give&nbsp;update&nbsp;access<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$bind&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ldap_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"cn=root,&nbsp;o=My&nbsp;Company,&nbsp;c=US"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"secret"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">$bind</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Unable&nbsp;to&nbsp;bind&nbsp;to&nbsp;LDAP&nbsp;server"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;use&nbsp;PASSWD&nbsp;EXOP&nbsp;to&nbsp;change&nbsp;the&nbsp;user&nbsp;password&nbsp;for&nbsp;a&nbsp;generated&nbsp;one<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$genpw&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ldap_exop_passwd</span><span style="color: #007700">(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"cn=root,&nbsp;o=My&nbsp;Company,&nbsp;c=US"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"secret"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$genpw</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;use&nbsp;the&nbsp;generated&nbsp;password&nbsp;to&nbsp;bind<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$bind&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ldap_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"cn=root,&nbsp;o=My&nbsp;Company,&nbsp;c=US"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$genpw</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;set&nbsp;the&nbsp;password&nbsp;back&nbsp;to&nbsp;"secret"<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">ldap_exop_passwd</span><span style="color: #007700">(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"cn=root,&nbsp;o=My&nbsp;Company,&nbsp;c=US"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$genpw</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"secret"</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">ldap_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">);<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Unable&nbsp;to&nbsp;connect&nbsp;to&nbsp;LDAP&nbsp;server"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.ldap-exop-passwd-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.ldap-exop.html" class="function" rel="rdfs-seeAlso">ldap_exop()</a> - Performs an extended operation</span></li>
    <li class="member"><span class="function"><a href="function.ldap-parse-exop.html" class="function" rel="rdfs-seeAlso">ldap_parse_exop()</a> - Parse result object from an LDAP extended operation</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>